package com.weekdo.moviecomic;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import android.util.Log;

public class ComicCenter {


	String[] comicEntryList;

	public ComicCenter() {
		try {
			unzipBasicinfo();
		} catch (ZipException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String[] getComicEntryList()
	{
		return comicEntryList;
	}


	public void unzipBasicinfo() throws ZipException, IOException {
		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return name.endsWith(".zip") || name.endsWith(".mck");
			}
		};

		//FileManager.delDirs(FileManager.MCK_VIEW_CACHE_DIR);
		FileManager.tryCreateDirs(FileManager.MCK_VIEW_CACHE_DIR);

		File archiveDir = new File(FileManager.MCK_ARCHIVE_DIR);
		File[] files = archiveDir.listFiles(filter);
		comicEntryList = new String[files.length];
		for (int i=0; i<files.length; i++)
		{
			String entryName = files[i].getName().replace(".zip", "").replace(".mck", "");
			this.comicEntryList[i] = entryName;
			
			String cacheDir = FileManager.MCK_VIEW_CACHE_DIR+"/"+entryName;
			FileManager.unzipToCacheDir(files[i], cacheDir);
		}

	}

}
